#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<stdlib.h>

int main()
{

  //  printf("I am a process...pid:%d\n",getpid());
  //  //程序替换
  //  execl("/home/fsp/linux-code/test/a.out","./a.out",NULL);
  //
  //  printf("HAHAHAHHAHAHHAHA!!!!\n");
  //  printf("HAHAHAHHAHAHHAHA!!!!\n");
  //  printf("HAHAHAHHAHAHHAHA!!!!\n");
  pid_t id = fork();
  if(id==0)
  {
    sleep(8);
    exit(1);
  }
  //father
  while(1){

    pid_t ret = waitpid(id,NULL,WNOHANG);
    if(ret>0)
    {
      printf("wait success!!!\n");
      break;

    }
    else if(ret==0)
    {
      //while(1){//父进程执行代码死循环在这，就不能再去轮询等了
        printf("father do nothing!!!\n");
        sleep(1);
     // }
    }
    else 
    {
      printf("wait failed\n");
      break;
    }
  }
  return 0;
}

